function covm = single_covmTS(R, HL, annual_factor)
% single_covmTS: Estimate full sample covariance matrix
% covm = single_covmTS(R, halflife, annual_factor)  Estimate EWMA 
% covariance matrix using last date in R for estimation date
% Example:
%    covm = single_covmTS(R, halflife, annual_factor);
%
% TODO: add separate vol and corr halflifes.  demeaning in a sensible way.
% consider capping outliers.  Turn daily return data into monthly covm TS 
% structure rather than daily covm TS.
%

N = length(R.dates);


% Build initial covm using halflife
if exist('HL','var')
    gamma = 0.5^(1/HL);
    decaypwr = (N-1:-1:0)';
    wgts = (gamma).^decaypwr;
    wgts = wgts/sum(wgts);
    init_covm = R.data'*diag(wgts)*R.data;
else
    error('no functionality for missing halflife yet.');
end

% Build covariance matrix time series
covm = buildTS(init_covm, R.header, R.dates(end));  % Covariance matrix


% Annualize
if exist('annual_factor','var')
    covm = multTS(covm, annual_factor);
end

return
